#include <iostream>
#include <string>
#include <unordered_map>

bool is_prime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int nearest_prime(int n) {
    int lower = n;
    int upper = n;
    while (true) {
        if (is_prime(lower)) {
            return lower;
        }
        if (is_prime(upper)) {
            return upper;
        }
        lower--;
        upper++;
    }
}

int convert_to_number(std::string words[]) {
    std::unordered_map<std::string, int> num_dict = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    int num = 0;
    for (int i = 0; i < 3; i++) {
        if (num_dict.find(words[i]) == num_dict.end()) {
            return -1;
        }
        num = num * 10 + num_dict[words[i]];
    }
    return num;
}

int main() {
    std::string input_words[3];
    std::cout << "Enter three words separated by spaces: ";
    for (int i = 0; i < 3; i++) {
        std::cin >> input_words[i];
    }

    int num = convert_to_number(input_words);
    if (num != -1 && 100 <= num && num <= 999) {
        int nearest = nearest_prime(num);
        if (nearest != -1) {
            std::cout << nearest << std::endl;
        } else {
            std::cout << "Wrong input" << std::endl;
        }
    } else {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}
